package com.lu.wemedia.controller.v1;


import com.lu.model.common.controller.BaseController;
import com.lu.model.common.dtos.ResponseResult;
import com.lu.model.wemedia.dto.WmArticleDto;
import com.lu.model.wemedia.dto.WmNewsDto;
import com.lu.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController extends BaseController {

    @Autowired
    private WmNewsService wmNewsService;


    /**
     * 查询用户发布的文章
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmArticleDto dto) {
        return wmNewsService.listArticle(dto);
    }

    /**
     * 发布文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }


    /**
     * 文章详细信息
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult message(@PathVariable Integer id) {
        return wmNewsService.message(id);
    }


    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return toResponse(wmNewsService.deleteById(id));
    }



    /**
     * 文章上下架
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }


}
